<template>
  <div>
    <h1 class="title">管理权限</h1>
    <div>
      <p class="item_title">管理员列表</p>
      <div class="item" v-for="item in users">
        <label>{{item.phone}}-{{item.name}}</label>
        <span class="time">
          <select v-model="item.accountStatus" @change="updateAdmin(item.accountStatus,item.id)">
            <option v-for="i in options" :value="i.value">{{i.label}}</option>
           </select>
        </span>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: "user-control",
    data() {
      return {
        users: [],
        options: [{
          value: '-1',
          label: '禁用'
        }, {
          value: '0',
          label: '正常'
        },
          {
            value: '1',
            label: '异常'
          }]
      }
    },
    created() {
      this.initUser()
    },
    methods: {
      initUser() {
        this.$post('/user/manager/admin/user/list', {pageIndex: 1, pageSize: 50}, res => {
          this.users = res
        })
      },
      updateAdmin(value, userId) {
        this.$post('/user/manager/admin/disable/user', {userId}, res => {
          this.$message({message: '修改成功', type: 'success'})
          this.initUser()
        })
      }
    }
  }
</script>

<style scoped>
  .title {
    font-size: 24px;
    font-weight: 700;
    margin: 0 0 20px 0;
  }

  .item {
    margin: 10px;
    padding: 5px;
    background: #E4E7ED;
  }

  .item_title {
    padding: 10px;
    font-size: 24px;
    font-weight: 900;
    text-align: center;
    background-color: #D2D2D2;
  }

  .time {
    float: right;
    font-size: 12px;
    color: #909399;
  }

  .time > select {
    width: 60px;
    height: 22px;
  }

</style>
